#INCLUDE_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR})

#-----------------------------------------------------------------------------
# Define zlib Library
#-----------------------------------------------------------------------------

add_definitions(
	-D_CRT_SECURE_NO_WARNINGS
	-DEXTERNAL_CODECS
	-DNO_REGISTRY
	-D_7ZIP_LARGE_PAGES
	-D_7ZIP_ST_9
)
add_definitions(
	-D_UNICODE
	-DUNICODE
)

set (7ZLIB_HEADERS
	SevenZip/SevenZipExtractorMemory.h
	SevenZip/FileStreamMemory.h
	SevenZip/ArchiveExtractCallbackMemory.h
	SevenZip/OutStreamWrapperMemory.h
	SevenZip/BlobBuffer.h
	SevenZip/ErpExcept.h	
	SevenZip/FileStream.h
	C/DllSecur.h
	C/7zCrc.h
	C/7zTypes.h
	C/Aes.h
	C/Alloc.h
	C/Bcj2.h
	C/Blake2.h
	C/Bra.h
	C/BwtSort.h
	C/Compiler.h
	C/CpuArch.h
	C/Delta.h
	C/HuffEnc.h
	C/LzFind.h
	C/LzFindMt.h
	C/LzHash.h
	C/Lzma2Dec.h
	C/Lzma2Enc.h
	C/LzmaDec.h
	C/LzmaEnc.h
	C/MtCoder.h
	C/Ppmd.h
	C/Ppmd7.h
	C/Ppmd8.h
	C/Precomp.h
	C/RotateDefs.h
	C/Sha1.h
	C/Sha256.h
	C/Sort.h
	C/Threads.h
	C/Xz.h
	C/XzCrc64.h
	C/XzEnc.h
	SevenZip/ArchiveExtractCallback.h
	SevenZip/ArchiveOpenCallback.h
	SevenZip/ArchiveUpdateCallback.h
	SevenZip/CompressionFormat.h
	SevenZip/CompressionLevel.h
	SevenZip/Enum.h
	SevenZip/FileInfo.h
	SevenZip/FileSys.h
	SevenZip/GUIDs.h
	SevenZip/InStreamWrapper.h
	SevenZip/ListCallback.h
	SevenZip/OutStreamWrapper.h
	SevenZip/PathScanner.h
	SevenZip/ProgressCallback.h
	SevenZip/PropVariant2.h
	SevenZip/SevenString.h
	SevenZip/SevenZipArchive.h
	SevenZip/SevenZipCompressor.h
	SevenZip/SevenZipException.h
	SevenZip/SevenZipExtractor.h
	SevenZip/SevenZipLister.h
	SevenZip/UsefulFunctions.h
	CPP/Common/Common.h
	CPP/Common/Defs.h
	CPP/Common/DynamicBuffer.h
	CPP/Common/DynLimBuf.h
	CPP/Common/IntToString.h
	CPP/Common/MyBuffer.h
	CPP/Common/MyCom.h
	CPP/Common/MyException.h
	CPP/Common/MyInitGuid.h
	CPP/Common/MyLinux.h
	CPP/Common/MyMap.h
	CPP/Common/MyString.h
	CPP/Common/MyTypes.h
	CPP/Common/MyUnknown.h
	CPP/Common/MyVector.h
	CPP/Common/MyWindows.h
	CPP/Common/MyXml.h
	CPP/Common/NewHandler.h
	CPP/Common/StringConvert.h
	CPP/Common/StringToInt.h
	CPP/Common/UTFConvert.h
	CPP/Common/Wildcard.h
	CPP/Windows/Defs.h
	CPP/Windows/FileDir.h
	CPP/Windows/FileFind.h
	CPP/Windows/FileIO.h
	CPP/Windows/FileName.h
	CPP/Windows/PropVariant.h
	CPP/Windows/PropVariantUtils.h
	CPP/Windows/Synchronization.h
	CPP/Windows/System.h
	CPP/Windows/Thread.h
	CPP/Windows/TimeUtils.h
	CPP/7zip/Archive/7z/7zCompressionMode.h
	CPP/7zip/Archive/7z/7zDecode.h
	CPP/7zip/Archive/7z/7zEncode.h
	CPP/7zip/Archive/7z/7zFolderInStream.h
	CPP/7zip/Archive/7z/7zHandler.h
	CPP/7zip/Archive/7z/7zHeader.h
	CPP/7zip/Archive/7z/7zIn.h
	CPP/7zip/Archive/7z/7zItem.h
	CPP/7zip/Archive/7z/7zOut.h
	CPP/7zip/Archive/7z/7zProperties.h
	CPP/7zip/Archive/7z/7zSpecStream.h
	CPP/7zip/Archive/7z/7zUpdate.h
	CPP/7zip/Archive/Cab/CabBlockInStream.h
	CPP/7zip/Archive/Cab/CabHandler.h
	CPP/7zip/Archive/Cab/CabHeader.h
	CPP/7zip/Archive/Cab/CabIn.h
	CPP/7zip/Archive/Cab/CabItem.h
	CPP/7zip/Archive/Chm/ChmHandler.h
	CPP/7zip/Archive/Chm/ChmIn.h
	CPP/7zip/Archive/Common/CoderMixer2.h
	CPP/7zip/Archive/Common/DummyOutStream.h
	CPP/7zip/Archive/Common/FindSignature.h
	CPP/7zip/Archive/Common/InStreamWithCRC.h
	CPP/7zip/Archive/Common/ItemNameUtils.h
	CPP/7zip/Archive/Common/MultiStream.h
	CPP/7zip/Archive/Common/OutStreamWithCRC.h
	CPP/7zip/Archive/Common/OutStreamWithSha1.h
	CPP/7zip/Archive/Common/ParseProperties.h
	CPP/7zip/Archive/DeflateProps.h
	CPP/7zip/Archive/HandlerCont.h
	CPP/7zip/Archive/IArchive.h
	CPP/7zip/Archive/Iso/IsoHandler.h
	CPP/7zip/Archive/Iso/IsoHeader.h
	CPP/7zip/Archive/Iso/IsoIn.h
	CPP/7zip/Archive/Iso/IsoItem.h
	CPP/7zip/Archive/Nsis/NsisDecode.h
	CPP/7zip/Archive/Nsis/NsisHandler.h
	CPP/7zip/Archive/Nsis/NsisIn.h
	CPP/7zip/Archive/Rar/Rar5Handler.h
	CPP/7zip/Archive/Rar/RarHandler.h
	CPP/7zip/Archive/Rar/RarHeader.h
	CPP/7zip/Archive/Rar/RarItem.h
	CPP/7zip/Archive/Rar/RarVol.h
	CPP/7zip/Archive/Tar/TarHandler.h
	CPP/7zip/Archive/Tar/TarHeader.h
	CPP/7zip/Archive/Tar/TarIn.h
	CPP/7zip/Archive/Tar/TarItem.h
	CPP/7zip/Archive/Tar/TarOut.h
	CPP/7zip/Archive/Tar/TarUpdate.h
	CPP/7zip/Archive/Udf/UdfHandler.h
	CPP/7zip/Archive/Udf/UdfIn.h
	CPP/7zip/Archive/Wim/WimHandler.h
	CPP/7zip/Archive/Wim/WimIn.h
	CPP/7zip/Archive/XzHandler.h
	CPP/7zip/Archive/Zip/ZipAddCommon.h
	CPP/7zip/Archive/Zip/ZipCompressionMode.h
	CPP/7zip/Archive/Zip/ZipHandler.h
	CPP/7zip/Archive/Zip/ZipHeader.h
	CPP/7zip/Archive/Zip/ZipIn.h
	CPP/7zip/Archive/Zip/ZipItem.h
	CPP/7zip/Archive/Zip/ZipOut.h
	CPP/7zip/Archive/Zip/ZipUpdate.h
	CPP/7zip/Common/CreateCoder.h
	CPP/7zip/Common/CWrappers.h
	CPP/7zip/Common/FilterCoder.h
	CPP/7zip/Common/InBuffer.h
	CPP/7zip/Common/InOutTempBuffer.h
	CPP/7zip/Common/LimitedStreams.h
	CPP/7zip/Common/MemBlocks.h
	CPP/7zip/Common/MethodId.h
	CPP/7zip/Common/MethodProps.h
	CPP/7zip/Common/OffsetStream.h
	CPP/7zip/Common/OutBuffer.h
	CPP/7zip/Common/OutMemStream.h
	CPP/7zip/Common/ProgressMt.h
	CPP/7zip/Common/ProgressUtils.h
	CPP/7zip/Common/RegisterArc.h
	CPP/7zip/Common/RegisterCodec.h
	CPP/7zip/Common/StreamBinder.h
	CPP/7zip/Common/StreamObjects.h
	CPP/7zip/Common/StreamUtils.h
	CPP/7zip/Common/UniqBlocks.h
	CPP/7zip/Common/VirtThread.h
	CPP/7zip/Compress/Bcj2Coder.h
	CPP/7zip/Compress/BcjCoder.h
	CPP/7zip/Compress/BitlDecoder.h
	CPP/7zip/Compress/BitlEncoder.h
	CPP/7zip/Compress/BitmDecoder.h
	CPP/7zip/Compress/BitmEncoder.h
	CPP/7zip/Compress/BranchMisc.h
	CPP/7zip/Compress/BZip2Const.h
	CPP/7zip/Compress/BZip2Crc.h
	CPP/7zip/Compress/BZip2Decoder.h
	CPP/7zip/Compress/BZip2Encoder.h
	CPP/7zip/Compress/CopyCoder.h
	CPP/7zip/Compress/DeflateConst.h
	CPP/7zip/Compress/DeflateDecoder.h
	CPP/7zip/Compress/DeflateEncoder.h
	CPP/7zip/Compress/HuffmanDecoder.h
	CPP/7zip/Compress/ImplodeDecoder.h
	CPP/7zip/Compress/ImplodeHuffmanDecoder.h
	CPP/7zip/Compress/LzhDecoder.h
	CPP/7zip/Compress/Lzma2Decoder.h
	CPP/7zip/Compress/Lzma2Encoder.h
	CPP/7zip/Compress/LzmaDecoder.h
	CPP/7zip/Compress/LzmaEncoder.h
	CPP/7zip/Compress/LzmsDecoder.h
	CPP/7zip/Compress/LzOutWindow.h
	CPP/7zip/Compress/Lzx.h
	CPP/7zip/Compress/LzxDecoder.h
	CPP/7zip/Compress/Mtf8.h
	CPP/7zip/Compress/PpmdDecoder.h
	CPP/7zip/Compress/PpmdEncoder.h
	CPP/7zip/Compress/PpmdZip.h
	CPP/7zip/Compress/QuantumDecoder.h
	CPP/7zip/Compress/Rar1Decoder.h
	CPP/7zip/Compress/Rar2Decoder.h
	CPP/7zip/Compress/Rar3Decoder.h
	CPP/7zip/Compress/Rar3Vm.h
	CPP/7zip/Compress/Rar5Decoder.h
	CPP/7zip/Compress/ShrinkDecoder.h
	CPP/7zip/Compress/XpressDecoder.h
	CPP/7zip/Compress/ZDecoder.h
	CPP/7zip/Compress/ZlibDecoder.h
	CPP/7zip/Compress/ZlibEncoder.h
	CPP/7zip/Crypto/7zAes.h
	CPP/7zip/Crypto/HmacSha1.h
	CPP/7zip/Crypto/HmacSha256.h
	CPP/7zip/Crypto/MyAes.h
	CPP/7zip/Crypto/Pbkdf2HmacSha1.h
	CPP/7zip/Crypto/RandGen.h
	CPP/7zip/Crypto/Rar20Crypto.h
	CPP/7zip/Crypto/Rar5Aes.h
	CPP/7zip/Crypto/RarAes.h
	CPP/7zip/Crypto/Sha1Cls.h
	CPP/7zip/Crypto/WzAes.h
	CPP/7zip/Crypto/ZipCrypto.h
	CPP/7zip/Crypto/ZipStrong.h
	CPP/7zip/ICoder.h
	CPP/7zip/IDecl.h
	CPP/7zip/IPassword.h
	CPP/7zip/IProgress.h
	CPP/7zip/IStream.h
	CPP/7zip/PropID.h
)

SET (7ZLIB_SRCS
	SevenZip/SevenZipExtractorMemory.cpp
	SevenZip/FileStreamMemory.cpp
	SevenZip/ArchiveExtractCallbackMemory.cpp
	SevenZip/OutStreamWrapperMemory.cpp
	SevenZip/BlobBuffer.cpp
	SevenZip/ErpExcept.cpp
	SevenZip/FileStream.cpp
	CPP/7zip/Archive/Iso/IsoHandler.cpp
	CPP/7zip/Archive/Tar/TarHandler.cpp
	CPP/7zip/Archive/Wim/WimHandler.cpp
	CPP/7zip/Archive/Zip/ZipHandler.cpp
	C/DllSecur.c
	C/7zBuf2.c
	C/7zCrc.c
	C/7zStream.c
	C/Aes.c
	C/Alloc.c
	C/Bcj2.c
	C/Bcj2Enc.c
	C/Blake2s.c
	C/Bra.c
	C/Bra86.c
	C/BraIA64.c
	C/BwtSort.c
	C/CpuArch.c
	C/Delta.c
	C/HuffEnc.c
	C/LzFind.c
	C/LzFindMt.c
	C/Lzma2Dec.c
	C/Lzma2Enc.c
	C/LzmaDec.c
	C/LzmaEnc.c
	C/MtCoder.c
	C/Ppmd7.c
	C/Ppmd7Dec.c
	C/Ppmd7Enc.c
	C/Ppmd8.c
	C/Ppmd8Dec.c
	C/Ppmd8Enc.c
	C/Sha1.c
	C/Sha256.c
	C/Sort.c
	C/Threads.c
	C/Xz.c
	C/XzCrc64.c
	C/XzCrc64Opt.c
	C/XzDec.c
	C/XzEnc.c
	C/XzIn.c
	SevenZip/ArchiveExtractCallback.cpp
	SevenZip/ArchiveOpenCallback.cpp
	SevenZip/ArchiveUpdateCallback.cpp
	SevenZip/FileSys.cpp
	SevenZip/GUIDs.cpp
	SevenZip/InStreamWrapper.cpp
	SevenZip/OutStreamWrapper.cpp
	SevenZip/PathScanner.cpp
	SevenZip/PropVariant2.cpp
	SevenZip/SevenZipArchive.cpp
	SevenZip/SevenZipCompressor.cpp
	SevenZip/SevenZipException.cpp
	SevenZip/SevenZipExtractor.cpp
	SevenZip/SevenZipLister.cpp
	SevenZip/UsefulFunctions.cpp
	CPP/Common/CRC.cpp
	CPP/Common/DynLimBuf.cpp
	CPP/Common/IntToString.cpp
	CPP/Common/MyMap.cpp
	CPP/Common/MyString.cpp
	CPP/Common/MyVector.cpp
	CPP/Common/MyWindows.cpp
	CPP/Common/MyXml.cpp
	CPP/Common/NewHandler.cpp
	CPP/Common/StringConvert.cpp
	CPP/Common/StringToInt.cpp
	CPP/Common/UTFConvert.cpp
	CPP/Common/Wildcard.cpp
	CPP/Windows/FileDir.cpp
	CPP/Windows/FileFind.cpp
	CPP/Windows/FileIO.cpp
	CPP/Windows/FileName.cpp
	CPP/Windows/PropVariant.cpp
	CPP/Windows/PropVariantUtils.cpp
	CPP/Windows/Synchronization.cpp
	CPP/Windows/System.cpp
	CPP/Windows/TimeUtils.cpp
	CPP/7zip/Archive/7z/7zCompressionMode.cpp
	CPP/7zip/Archive/7z/7zDecode.cpp
	CPP/7zip/Archive/7z/7zEncode.cpp
	CPP/7zip/Archive/7z/7zExtract.cpp
	CPP/7zip/Archive/7z/7zFolderInStream.cpp
	CPP/7zip/Archive/7z/7zHandler.cpp
	CPP/7zip/Archive/7z/7zHeader.cpp
	CPP/7zip/Archive/7z/7zIn.cpp
	CPP/7zip/Archive/7z/7zOut.cpp
	CPP/7zip/Archive/7z/7zProperties.cpp
	CPP/7zip/Archive/7z/7zSpecStream.cpp
	CPP/7zip/Archive/7z/7zUpdate.cpp
	CPP/7zip/Archive/7z/7zHandlerOut.cpp
	CPP/7zip/Archive/ArchiveExports.cpp
	CPP/7zip/Archive/Cab/CabBlockInStream.cpp
	CPP/7zip/Archive/Cab/CabHandler.cpp
	CPP/7zip/Archive/Cab/CabHeader.cpp
	CPP/7zip/Archive/Cab/CabIn.cpp
	CPP/7zip/Archive/Chm/ChmIn.cpp
	CPP/7zip/Archive/Common/CoderMixer2.cpp
	CPP/7zip/Archive/Common/DummyOutStream.cpp
	CPP/7zip/Archive/Common/FindSignature.cpp
	CPP/7zip/Archive/Common/HandlerOut.cpp
	CPP/7zip/Archive/Common/InStreamWithCRC.cpp
	CPP/7zip/Archive/Common/ItemNameUtils.cpp
	CPP/7zip/Archive/Common/MultiStream.cpp
	CPP/7zip/Archive/Common/OutStreamWithCRC.cpp
	CPP/7zip/Archive/Common/OutStreamWithSha1.cpp
	CPP/7zip/Archive/Common/ParseProperties.cpp
	CPP/7zip/Archive/DeflateProps.cpp
	CPP/7zip/Archive/DllExports2.cpp
	CPP/7zip/Archive/HandlerCont.cpp
	CPP/7zip/Archive/Iso/IsoHeader.cpp
	CPP/7zip/Archive/Iso/IsoIn.cpp
	CPP/7zip/Archive/Nsis/NsisDecode.cpp
	CPP/7zip/Archive/Nsis/NsisHandler.cpp
	CPP/7zip/Archive/Nsis/NsisIn.cpp
	CPP/7zip/Archive/Tar/TarHandlerOut.cpp
	CPP/7zip/Archive/Tar/TarHeader.cpp
	CPP/7zip/Archive/Tar/TarIn.cpp
	CPP/7zip/Archive/Tar/TarOut.cpp
	CPP/7zip/Archive/Tar/TarUpdate.cpp
	CPP/7zip/Archive/Udf/UdfIn.cpp
	CPP/7zip/Archive/Wim/WimHandlerOut.cpp
	CPP/7zip/Archive/Wim/WimIn.cpp
	CPP/7zip/Archive/Zip/ZipAddCommon.cpp
	CPP/7zip/Archive/Zip/ZipHandlerOut.cpp
	CPP/7zip/Archive/Zip/ZipIn.cpp
	CPP/7zip/Archive/Zip/ZipItem.cpp
	CPP/7zip/Archive/Zip/ZipOut.cpp
	CPP/7zip/Archive/Zip/ZipUpdate.cpp
	CPP/7zip/Common/CreateCoder.cpp
	CPP/7zip/Common/CWrappers.cpp
	CPP/7zip/Common/FilterCoder.cpp
	CPP/7zip/Common/InBuffer.cpp
	CPP/7zip/Common/InOutTempBuffer.cpp
	CPP/7zip/Common/LimitedStreams.cpp
	CPP/7zip/Common/MemBlocks.cpp
	CPP/7zip/Common/MethodId.cpp
	CPP/7zip/Common/MethodProps.cpp
	CPP/7zip/Common/OffsetStream.cpp
	CPP/7zip/Common/OutBuffer.cpp
	CPP/7zip/Common/OutMemStream.cpp
	CPP/7zip/Common/ProgressMt.cpp
	CPP/7zip/Common/ProgressUtils.cpp
	CPP/7zip/Common/PropId.cpp
	CPP/7zip/Common/StreamBinder.cpp
	CPP/7zip/Common/StreamObjects.cpp
	CPP/7zip/Common/StreamUtils.cpp
	CPP/7zip/Common/UniqBlocks.cpp
	CPP/7zip/Common/VirtThread.cpp
	CPP/7zip/Compress/Bcj2Coder.cpp
	CPP/7zip/Compress/BcjCoder.cpp
	CPP/7zip/Compress/BitlDecoder.cpp
	CPP/7zip/Compress/BranchMisc.cpp
	CPP/7zip/Compress/BZip2Crc.cpp
	CPP/7zip/Compress/BZip2Decoder.cpp
	CPP/7zip/Compress/BZip2Encoder.cpp
	CPP/7zip/Compress/CodecExports.cpp
	CPP/7zip/Compress/CopyCoder.cpp
	CPP/7zip/Compress/DeflateDecoder.cpp
	CPP/7zip/Compress/DeflateEncoder.cpp
	CPP/7zip/Compress/ImplodeDecoder.cpp
	CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp
	CPP/7zip/Compress/LzhDecoder.cpp
	CPP/7zip/Compress/Lzma2Decoder.cpp
	CPP/7zip/Compress/Lzma2Encoder.cpp
	CPP/7zip/Compress/LzmaDecoder.cpp
	CPP/7zip/Compress/LzmaEncoder.cpp
	CPP/7zip/Compress/LzmsDecoder.cpp
	CPP/7zip/Compress/LzOutWindow.cpp
	CPP/7zip/Compress/LzxDecoder.cpp
	CPP/7zip/Compress/PpmdDecoder.cpp
	CPP/7zip/Compress/PpmdEncoder.cpp
	CPP/7zip/Compress/PpmdZip.cpp
	CPP/7zip/Compress/QuantumDecoder.cpp
	CPP/7zip/Compress/Rar1Decoder.cpp
	CPP/7zip/Compress/Rar2Decoder.cpp
	CPP/7zip/Compress/Rar3Decoder.cpp
	CPP/7zip/Compress/Rar3Vm.cpp
	CPP/7zip/Compress/Rar5Decoder.cpp
	CPP/7zip/Compress/ShrinkDecoder.cpp
	CPP/7zip/Compress/XpressDecoder.cpp
	CPP/7zip/Compress/ZDecoder.cpp
	CPP/7zip/Compress/ZlibDecoder.cpp
	CPP/7zip/Compress/ZlibEncoder.cpp
	CPP/7zip/Crypto/7zAes.cpp
	CPP/7zip/Crypto/HmacSha1.cpp
	CPP/7zip/Crypto/HmacSha256.cpp
	CPP/7zip/Crypto/MyAes.cpp
	CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp
	CPP/7zip/Crypto/RandGen.cpp
	CPP/7zip/Crypto/Rar20Crypto.cpp
	CPP/7zip/Crypto/Rar5Aes.cpp
	CPP/7zip/Crypto/RarAes.cpp
	CPP/7zip/Crypto/WzAes.cpp
	CPP/7zip/Crypto/ZipCrypto.cpp
	CPP/7zip/Crypto/ZipStrong.cpp
	CPP/7zip/Crypto/7zAesRegister.cpp
)

if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64")
SET (7ZLIB_SRCS
	${7ZLIB_SRCS}
	C/7zCrcOpt.c
	C/AesOpt.c
)
else()
ENABLE_LANGUAGE(ASM_MASM)
set(7ZIP_ASMS
	Asm/x86/7zCrcOpt.asm
	Asm/x86/AesOpt.asm
)
endif()

if (CMAKE_CL_64)
add_definitions(-Dx64)
endif()

source_group("Header Files" FILES ${7ZLIB_HEADERS})
source_group("Source Files" FILES ${7ZLIB_SRCS})
source_group("Asms Files" FILES ${7ZIP_ASMS})

ADD_LIBRARY (7z STATIC ${7ZLIB_SRCS} ${7ZLIB_HEADERS} ${7ZIP_ASMS})
set(COM_LIBS ${COM_LIBS} 7z CACHE INTERNAL "com_lib")
set_target_properties (7z PROPERTIES
    FOLDER third-part
)

install(TARGETS 7z
    CONFIGURATIONS Release
    RUNTIME DESTINATION bin/Release
    LIBRARY DESTINATION lib/Release
    ARCHIVE DESTINATION lib/Release
)

install(TARGETS 7z
    CONFIGURATIONS Debug
    RUNTIME DESTINATION bin/Debug
    LIBRARY DESTINATION lib/Debug
    ARCHIVE DESTINATION lib/Debug
)
